
#include  	"main.h"
#include 	"system.h"
#include 	"Communication.h"

CollectedData	collectData;
uint16_t	VREFINT_CAL;
char firmwareInf[3][20]={{FW_VERSION},{__DATE__},{__TIME__}};

CollectedData     	ReceData={0};
CollectedDataType	ReceDataType={0};

ChannleWarnStatus	WarnStatus={0};
AllLedStatus		LedStatus={0};
KeyStatus			KeyStatu={0};
MenuStatus			LcdMenuStatus=Menu_Inital;
Sys_Para			SysPara;

/********************************************
SetThresholdValue
Date:20200316163701
TemThreshold_a:40
TemThreshold_b:40
TemThreshold_c:40
TemThreshold_s:50
Vol_OverThreshold_a:240
Vol_BelowThreshold_a:200
Vol_OverThreshold_b:240
Vol_BelowThreshold_b:200
Vol_OverThreshold_c:240
Vol_BelowThreshold_c:200
CurThreshold_a:100
CurThreshold_b:100
CurThreshold_c:100
CurThreshold_s:1.5
PowerThreshold:80000
OK
*********************************************/
void LcdShowData(void)
{
	if(CollectBoard_ReceData->len>=22+7)
	{
		
		ResppackRece=0;
		ReceDataType=GetCollectedResult(&ReceData);
		if(ReceDataType==CurrentValue)	
		{	
			
			/*printf("Ia=%d\n",ReceData.CurData.aVal);
			printf("Ib=%d\n",ReceData.CurData.bVal);
			printf("Ic=%d\n",ReceData.CurData.cVal);
			printf("Ir=%d\n",ReceData.CurData.rVal);
			printf("IS=%d\n",ReceData.SignalStrength);
			printf("IO=%d\n",ReceData.OnLineFlag);*/
			UpataResidualsCurrentData();			
				
		}
		else if(ReceDataType==VoltageValue) 
		{
			/*
			printf("Va=%d\n",ReceData.VolData.aVal);
			printf("Vb=%d\n",ReceData.VolData.bVal);
			printf("Vc=%d\n",ReceData.VolData.cVal);
			*/
			UpataCurrentAndVoltageData();
			
		}
		else if(ReceDataType==TemperatureValue) 
		{
			/*
			printf("Ta=%d\n",ReceData.TemData.aVal);
			printf("Tb=%d\n",ReceData.TemData.bVal);
			printf("Tc=%d\n",ReceData.TemData.cVal);
			printf("TS=%d\n",ReceData.TemData.sVal);
			*/
			UpataTemperatureData();
		}

	   CollectBoard_ReceData->len=0;
	   memset(CollectBoard_ReceData->buf,0,Uart_ReceBufLen);
	}

	�� ��������
	if(WarnStatus.CurChannle_a_Warn!=Cur_Warn_OverCurrent\
	 && WarnStatus.CurChannle_b_Warn!=Cur_Warn_OverCurrent\
	  &&	WarnStatus.CurChannle_c_Warn!=Cur_Warn_OverCurrent\
	   &&	WarnStatus.CurChannle_r_Warn!=Cur_Warn_OverCurrent\
	   
		&&	WarnStatus.VolChannle_a_Warn!=Vol_Warn_OverVoltage\
		 && WarnStatus.VolChannle_b_Warn!=Vol_Warn_OverVoltage\
		  &&WarnStatus.VolChannle_c_Warn!=Vol_Warn_OverVoltage\
		  
		   &&	WarnStatus.TemChannle_a_Warn!=Tem_Warn_OverHigh\
			&&	WarnStatus.TemChannle_b_Warn!=Tem_Warn_OverHigh\
			 && WarnStatus.TemChannle_c_Warn!=Tem_Warn_OverHigh\
			  &&WarnStatus.TemChannle_s_Warn!=Tem_Warn_OverHigh)
	{

		if(LedStatus.alarm_led==LED_Enable)
		{
			LedStatus.alarm_led=LED_Disable;
			HAL_Delay(1000);
			BUZZER_OFF;
			Led_Alarm_OFF;
		}
		/*LedStatus.malfunction_led=LED_Disable;
		LedStatus.missingPhase_led=LED_Disable;
		Led_Alarm_OFF;
		Led_Malfunction_OFF;*/
		if(SysPara.sendAlarmInforFlag==1)
		{
			printf("\n\n-->>���ͱ����������\n");
			SendDataToCollectBoard(Cmd2SendDataToServer,strlen(Cmd2SendDataToServer));
			HAL_Delay(2000);

			if(CollectBoard_ReceData->len>0)
			{
				CollectBoard_ReceData->buf[CollectBoard_ReceData->len]=0;
				printf("-->>%s\n",CollectBoard_ReceData->buf);

				#if 1
				if(UtilFindStringContent(CollectBoard_ReceData->buf,CollectBoard_ReceData->len,Cmd2SuccessAck)==TRUE)
				{
					
					CollectBoard_ReceData->len=0;
					SysPara.sendAlarmInforFlag=0;

				}

				#else
				if (strstr(CollectBoard_ReceData->buf,Cmd2SuccessAck)!=NULL )
				{
					printf("\n\n-->>222222222222\n");
					CollectBoard_ReceData->len=0;
					SysPara.sendAlarmInforFlag=0;
				}
				#endif
			}

			
		}

	}


	����û�й���
	if(WarnStatus.CurChannle_a_Warn!=Cur_Warn_NoSensor\
		 && WarnStatus.CurChannle_b_Warn!=Cur_Warn_NoSensor\
		  &&	WarnStatus.CurChannle_c_Warn!=Cur_Warn_NoSensor\
		   &&	WarnStatus.CurChannle_r_Warn!=Cur_Warn_NoSensor\
		   
			&&	WarnStatus.VolChannle_a_Warn!=Vol_Warn_UnderVoltage\
			 && WarnStatus.VolChannle_b_Warn!=Vol_Warn_UnderVoltage\
			  &&WarnStatus.VolChannle_c_Warn!=Vol_Warn_UnderVoltage\
			  
			   &&	WarnStatus.TemChannle_a_Warn!=Tem_Warn_NoSensor\
				&&	WarnStatus.TemChannle_b_Warn!=Tem_Warn_NoSensor\
				 && WarnStatus.TemChannle_c_Warn!=Tem_Warn_NoSensor\
				  &&WarnStatus.TemChannle_s_Warn!=Tem_Warn_NoSensor)
	{
		if(LedStatus.malfunction_led==LED_Enable)
		{
			LedStatus.malfunction_led=LED_Disable;
			HAL_Delay(1000);
			Led_Malfunction_OFF;
		}
	}
	������ȱ��
	if(ReceData.VolData.aVal>Voltage_Zero_Point\
			 && ReceData.VolData.bVal>Voltage_Zero_Point\
			  &&ReceData.VolData.cVal>Voltage_Zero_Point)
	{
		if(LedStatus.missingPhase_led==LED_Enable)
		{
			LedStatus.missingPhase_led=LED_Disable;
			HAL_Delay(1000);
			Led_MissPhase_OFF;
		}
	}
	
	��һ������
	if(WarnStatus.CurChannle_a_Warn==Cur_Warn_OverCurrent\
	 || WarnStatus.CurChannle_b_Warn==Cur_Warn_OverCurrent\
	  ||	WarnStatus.CurChannle_c_Warn==Cur_Warn_OverCurrent\
	   ||	WarnStatus.CurChannle_r_Warn==Cur_Warn_OverCurrent\
	   
		||	WarnStatus.VolChannle_a_Warn==Vol_Warn_OverVoltage\
		 || WarnStatus.VolChannle_b_Warn==Vol_Warn_OverVoltage\
		  ||WarnStatus.VolChannle_c_Warn==Vol_Warn_OverVoltage\
		  
		   ||	WarnStatus.TemChannle_a_Warn==Tem_Warn_OverHigh\
			||	WarnStatus.TemChannle_b_Warn==Tem_Warn_OverHigh\
			 || WarnStatus.TemChannle_c_Warn==Tem_Warn_OverHigh\
			  ||WarnStatus.TemChannle_s_Warn==Tem_Warn_OverHigh)	 
	{

		if(SysPara.sendAlarmInforFlag==0)�з��ͱ������ݡ�
		{
			printf("\n\n-->>���ͱ�������\n");
			SendDataToCollectBoard(Cmd2SendDataToServer,strlen(Cmd2SendDataToServer));
			HAL_Delay(2000);

			if(CollectBoard_ReceData->len>0)
			{
				CollectBoard_ReceData->buf[CollectBoard_ReceData->len]=0;
				printf("-->>%s\n",CollectBoard_ReceData->buf);

				#if 1
				if(UtilFindStringContent(CollectBoard_ReceData->buf,CollectBoard_ReceData->len,Cmd2SuccessAck)==TRUE)
				{
					
					CollectBoard_ReceData->len=0;
					SysPara.sendAlarmInforFlag=1;


				}

				#else
				if (strstr(CollectBoard_ReceData->buf,Cmd2SuccessAck)!=NULL )
				{

					printf("\n\n-->>44444444444444\n");
					CollectBoard_ReceData->len=0;
					SysPara.sendAlarmInforFlag=1;
				}
				#endif
			}


			
		}

	}

	
	if(KeyStatu.Menu_Key_LongPress)
	{
	   KeyStatu.Menu_Key_LongPress=0;
	   LcdMenuStatus=Menu_EnterSet;
	}

	if(KeyStatu.Move_Key_Press)
	{
	   KeyStatu.Move_Key_Press=0;
	   LcdMenuStatus=Menu_ShowSysInfor;
	}

	
}

void LcdEnterMenu(void)
{
	uint8	i=0,x=0,y=0,reverse_xpoint=0,channle=0,select;
	uint16 temp1,temp2;
	x=1;y=0,reverse_xpoint=x;
	
	DisplayMenu:
	
	disp_clear();
	DisplayStr(0,4,76,1,0);
	DisplayStr(0,5,64,1,0);
	DisplayStr(0,6,72,1,0);
	DisplayStr(0,7,77,1,0);
	DisplayStr(0,8,76,1,0);
	DisplayStr(0,9,68,1,0);
	DisplayStr(0,10,77,1,0);
	DisplayStr(0,11,84,1,0);
	
	
	DisplayChinesCharacter(x,y,52,reverse_xpoint==x?1:0);
	DisplayChinesCharacterRightShift8bit(x,y+1,16,reverse_xpoint==x?1:0);
	DisplayChinesCharacter(x,y+1,17,reverse_xpoint==x?1:0);
	DisplayChinesCharacter_s(x,y+2,53,5,reverse_xpoint==x?1:0);��������Ϣ 
	
	
	
	DisplayChinesCharacter(x+2,y+0,52,reverse_xpoint==(x+2)?1:0);
	DisplayChinesCharacterRightShift8bit(x+2,y+1,16,reverse_xpoint==(x+2)?1:0);
	DisplayChinesCharacter(x+2,y+1,16+9,reverse_xpoint==(x+2)?1:0);
	DisplayChinesCharacter_s(x+2,y+2,36,2,reverse_xpoint==(x+2)?1:0);���� 
	DisplayChinesCharacter_s(x+2,y+4,58,2,reverse_xpoint==(x+2)?1:0);��ֵ
	
	DisplayChinesCharacter(x+4,y+0,52,(reverse_xpoint==(x+4)?1:0));
	DisplayChinesCharacterRightShift8bit(x+4,y+1,17,reverse_xpoint==(x+4)?1:0);
	DisplayChinesCharacter(x+4,y+1,16+2,reverse_xpoint==(x+4)?1:0);
	DisplayChinesCharacter_s(x+4,y+2,60,4,reverse_xpoint==(x+4)?1:0);����
	
	
	
	KeyStatu.Menu_Key_ShortPress=0;
	KeyStatu.Menu_Key_LongPress=0;
	KeyStatu.Move_Key_Press=0;
	KeyStatu.Select_Key_Press=0;
	while(1)
	{
		
		if(KeyStatu.Menu_Key_LongPress|KeyStatu.Menu_Key_ShortPress)
		{
			KeyStatu.Menu_Key_LongPress=0;
			KeyStatu.Menu_Key_ShortPress=0;
			LcdMenuStatus=Menu_ShowData;
			disp_clear();
			break;
		}
		if(KeyStatu.Move_Key_Press)
		{
			
			KeyStatu.Move_Key_Press=0;
			reverse_xpoint+=2;
			if(reverse_xpoint==x+6)
			{
				reverse_xpoint=x;
			}
			
			goto DisplayMenu;
		}
		if(KeyStatu.Select_Key_Press)
		{
			printf("Select_Key_Press\n");
			KeyStatu.Select_Key_Press=0;
			if(reverse_xpoint==x)
			{
				printf("��������Ϣ\n");
				
				channle=1;

				DisplaySensor:
				printf("BBB\n");
				disp_clear();
				DisplayStr(0,0,0,16,1);��
				if(channle<10)
				{
				  DisplayStr(0,1,16+channle,1,1);
				}
				else
				{
					DisplayStr(0,0,16+1,1,1);
					DisplayStr(0,1,16+channle-10,1,1);
				}
				DisplayStr(0,2,15,1,1);
				DisplayStr(0,3,16+1,1,1);
				DisplayStr(0,4,16+1,1,1);

				DisplayChinesCharacter(2,0,11,0);
				DisplayChinesCharacterRightShift8bit(2,1,64,0);
				DisplayChinesCharacter(2,1,26,0);

				if(channle==1)
				{

		
					DisplayStr(0,15,16+channle,1,1);��һ���ұ�
							
					DisplayChinesCharacterRightShift8bit(2,2,16+channle,0);
					
					DisplayChinesCharacter_s(4,0,29,4,0);��
					DisplayChinesCharacter_s(4,2,0,2,0);����

					
					DisplayChinesCharacter_s(6,0,65,2,0);����
					DisplayChinesCharacter(6,2,26,0);
					DisplayChinesCharacterRightShift8bit(6,3,17,0);
					DisplayChinesCharacterRightShift8bit(6,4,16,0);
					DisplayChinesCharacterRightShift8bit(6,5,16,0);
					DisplayChinesCharacterRightShift8bit(6,6,16,0);
					DisplayChinesCharacter_s(6,6,31,2,0);
				}
				else	if(channle==2||channle==3||channle==4||channle==5)
				{

					DisplayStr(0,15,16+channle,1,1);��һ���ұ�
					

					
					DisplayChinesCharacterRightShift8bit(2,2,16+channle,0);
					
					DisplayChinesCharacter_s(4,0,67,2,0);�¶�
					DisplayChinesCharacter_s(4,2,69,2,0);
					DisplayChinesCharacter(4,4,11,0);
					
					DisplayChinesCharacter_s(6,0,65,2,0);����
					DisplayChinesCharacter(6,2,26,0);
					DisplayChinesCharacterRightShift8bit(6,3,17,0);
					DisplayChinesCharacterRightShift8bit(6,4,16+5,0);
					DisplayChinesCharacterRightShift8bit(6,5,16,0);
					
					DisplayChinesCharacterRightShift8bit(6,6,27,0);
					

				}
				else	if(channle==6||channle==7||channle==8)
				{
					if(channle==6)��һ���ұ�	
					{
						DisplayStr(0,14,54,1,1);
						DisplayStr(0,15,33,1,1);
						DisplayChinesCharacter(2,2,71,0);
						DisplayChinesCharacterRightShift8bit(2,3,9,0);
					}
					if(channle==7)��һ���ұ�	
					{
						DisplayStr(0,14,54,1,1);
						DisplayStr(0,15,34,1,1);
						DisplayChinesCharacter(2,2,71,0);
						DisplayChinesCharacterRightShift8bit(2,3,10,0); 							
					}
					
					if(channle==8)��һ���ұ�	
					{
						DisplayStr(0,14,54,1,1);
						DisplayStr(0,15,35,1,1);
						DisplayChinesCharacter(2,2,71,0);
						DisplayChinesCharacterRightShift8bit(2,3,11,0); 										
					}
					
			
					DisplayChinesCharacter(4,0,0,0);��ѹ
					DisplayChinesCharacter(4,1,2,0);

					
					DisplayChinesCharacter_s(6,0,65,2,0);����
					DisplayChinesCharacter(6,2,26,0);
					DisplayChinesCharacterRightShift8bit(6,3,16+5,0);
					DisplayChinesCharacterRightShift8bit(6,4,16,0);
					DisplayChinesCharacterRightShift8bit(6,5,16,0);
					DisplayChinesCharacterRightShift8bit(6,6,71,0);
					
				}
				else	if(channle==9||channle==10||channle==11)
				{
					if(channle==9)��һ���ұ�	
					{
						DisplayStr(0,14,41,1,1);
						DisplayStr(0,15,33,1,1);
						DisplayChinesCharacter(2,2,72,0);
						DisplayChinesCharacterRightShift8bit(2,3,9,0);
					}
					if(channle==10)��һ���ұ� 
					{
						DisplayStr(0,14,41,1,1);
						DisplayStr(0,15,34,1,1);
						DisplayChinesCharacter(2,2,72,0);
						DisplayChinesCharacterRightShift8bit(2,3,10,0); 							
					}
					
					if(channle==11)��һ���ұ� 
					{
						DisplayStr(0,14,41,1,1);
						DisplayStr(0,15,35,1,1);
						DisplayChinesCharacter(2,2,72,0);
						DisplayChinesCharacterRightShift8bit(2,3,11,0); 										
					}
					
			
					DisplayChinesCharacter(4,0,0,0);��ѹ
					DisplayChinesCharacter(4,1,2,0);

					
					DisplayChinesCharacter_s(6,0,65,2,0);����
					DisplayChinesCharacter(6,2,26,0);
					DisplayChinesCharacterRightShift8bit(6,3,16+1,0);
					DisplayChinesCharacterRightShift8bit(6,4,16,0);
					DisplayChinesCharacterRightShift8bit(6,5,16,0);
					DisplayChinesCharacterRightShift8bit(6,6,32,0);
					

				}

				while(1)
				{
					printf("CCC\n");
					if(KeyStatu.Menu_Key_LongPress|KeyStatu.Menu_Key_ShortPress)
					{
						KeyStatu.Menu_Key_LongPress=0;
						KeyStatu.Menu_Key_ShortPress=0;
						
						goto DisplayMenu;
					}
					if(KeyStatu.Move_Key_Press)
					{
						
						KeyStatu.Move_Key_Press=0;
						++channle;
						if(channle>11)
						{
							channle=1;
						}
						printf("AAA\n");
						goto DisplaySensor;
					}
					if(KeyStatu.Select_Key_Press)
					{
										
					}
					HAL_Delay(1000);
				}
				
				
			}
			else if(reverse_xpoint==(x+2)) 
			{
				printf("������ֵ\n");
				disp_clear();
				
				DisplayChinesCharacter(0,0,17,0);
				DisplayChinesCharacter(2,0,18,0);
				DisplayChinesCharacter(4,0,19,0);
				DisplayChinesCharacter(6,0,20,0);

				
				select=0;
				channle=1;
				DisplayChinesCharacter(select,1,73,0);�ƶ��ڷ���
				DisplayChinesCharacter(2,1,74,0);
				DisplayChinesCharacter(4,1,74,0);
				DisplayChinesCharacter(6,1,74,0);

				DisplayChannleLimitValue:
				if(channle==1)
				{


					DisplayChinesCharacter_s(0,2,29,2,0);�����
					DisplayChinesCharacter_s(0,4,0,2,0);

					DisplayChinesCharacter(2,2,77,0);��λ
					DisplayChinesCharacter(2,3,78,0);
					DisplayChinesCharacter(2,4,26,0);
					DisplayChinesCharacter_s(2,5,31,2,0);

					DisplayChinesCharacter(4,2,36,0);����ֵ
					DisplayChinesCharacter(4,3,37,0);
					DisplayChinesCharacter(4,4,59,0);
					DisplayChinesCharacter(4,5,26,0);


					DisplayDataCompact(4,6,SysPara.thresholdVal.CurThreshold_r);


	
					
				}
				else if(channle==2||channle==3||channle==4||channle==5) 
				{

				

					DisplayChinesCharacter_s(0,2,67,2,0);�¶�
					DisplayChinesCharacter_s(0,4,69,1,0);
					DisplayChinesCharacterRightShift8bit(0,5,70,0);
					DisplayChinesCharacter(0,5,11,0);


					DisplayChinesCharacter(2,2,77,0);��λ
					DisplayChinesCharacter(2,3,78,0);
					DisplayChinesCharacter(2,4,26,0);
					DisplayChinesCharacter_s(2,5,27,1,0);��
					DisplayChinesCharacter(2,6,51,0);��

					DisplayChinesCharacter(4,2,36,0);����ֵ
					DisplayChinesCharacter(4,3,37,0);
					DisplayChinesCharacter(4,4,59,0);
					DisplayChinesCharacter(4,5,26,0);

					if(channle==2)
					{
						temp1=SysPara.thresholdVal.TemThreshold_a/10;
					}
					else if(channle==3)
					{
						temp1=SysPara.thresholdVal.TemThreshold_b/10;
					}if(channle==4)
					{
						temp1=SysPara.thresholdVal.TemThreshold_c/10;
					}if(channle==5)
					{
						temp1=SysPara.thresholdVal.TemThreshold_s/10;
					}

					if(temp1>100)
					{
						DisplayChinesCharacterLeftShift8bit(4,5,16+(temp1/100)%10);
					}
					DisplayChinesCharacter(4,6,16+(temp1/10)%10,0);

					DisplayChinesCharacterLeftShift8bit(4,6,16+temp1%10,0);

					DisplayChinesCharacter(4,7,28,0);
					
					DisplayChinesCharacterLeftShift8bit(4,7,16,0);	
					

				}
				else if(channle==6||channle==7||channle==8) 
				{

					if(channle==6)
					{
						temp1=SysPara.thresholdVal.Vol_OverThreshold_a;
						temp2=SysPara.thresholdVal.Vol_BelowThreshold_a;
					}
					else if(channle==7)
					{
						temp1=SysPara.thresholdVal.Vol_OverThreshold_b;
						temp2=SysPara.thresholdVal.Vol_BelowThreshold_b;
					}if(channle==8)
					{
						temp1=SysPara.thresholdVal.Vol_OverThreshold_c;
						temp2=SysPara.thresholdVal.Vol_BelowThreshold_c;
					}				 

					
					DisplayChinesCharacter(0,2,0,0);��ѹ
					DisplayChinesCharacter(0,3,2,0);
					DisplayChinesCharacter(0,4,51,0);��
					DisplayChinesCharacter(0,5,51,0);


					DisplayChinesCharacter(2,2,77,0);��λ
					DisplayChinesCharacter(2,3,78,0);
					DisplayChinesCharacter(2,4,26,0);
					DisplayChinesCharacter(2,5,71,0);
					DisplayChinesCharacter(2,6,51,0);��


					DisplayChinesCharacter(4,2,79,0);
					DisplayChinesCharacter(4,3,2,0);
					DisplayChinesCharacter(4,4,59,0);
					DisplayChinesCharacter(4,5,26,0);
					
					DisplayChinesCharacterRightShift8bit(4,6,16+temp2/100,0);
					DisplayChinesCharacter(4,6,16+(temp2/10)%10,0);

					DisplayChinesCharacter(4,7,51,0);��
					
					DisplayChinesCharacterRightShift8bit(4,7,16+temp2%10,0);	


					DisplayChinesCharacter(6,2,80,0);��ѹֵ
					DisplayChinesCharacter(6,3,2,0);
					DisplayChinesCharacter(6,4,59,0);
					DisplayChinesCharacter(6,5,26,0);
					
					DisplayChinesCharacterRightShift8bit(6,6,16+temp1/100,0);
					DisplayChinesCharacter(6,6,16+(temp1/10)%10,0);
					DisplayChinesCharacterRightShift8bit(6,7,16+temp1%10,0);									

				}
				else if(channle==9||channle==10||channle==11)	
				{

					if(channle==9)
					{
						
						temp1=SysPara.thresholdVal.CurThreshold_a;
					}
					else if(channle==10)
					{
						
						temp1=SysPara.thresholdVal.CurThreshold_b;
					}if(channle==11)
					{
						
						temp1=SysPara.thresholdVal.CurThreshold_c;
					}



					DisplayChinesCharacter(0,2,0,0);����
					DisplayChinesCharacter(0,3,1,0);
					DisplayChinesCharacter(0,4,51,0);��
					DisplayChinesCharacter(0,5,51,0);


					DisplayChinesCharacter(2,2,77,0);��λ
					DisplayChinesCharacter(2,3,78,0);
					DisplayChinesCharacter(2,4,26,0);
					DisplayChinesCharacter(2,5,32,0);
					DisplayChinesCharacter(2,6,51,0);��


					DisplayChinesCharacter(4,2,36,0);����ֵ
					DisplayChinesCharacter(4,3,37,0);
					DisplayChinesCharacter(4,4,59,0);
					DisplayChinesCharacter(4,5,26,0);
					DisplayChinesCharacterRightShift8bit(4,6,16+temp1/10,0);
					DisplayChinesCharacter(4,6,16+temp1%10,0);
					
					DisplayChinesCharacterRightShift8bit(4,7,51,0);��

					DisplayChinesCharacter(4,7,51,0);��
					
					DisplayChinesCharacter(6,2,51,0);��
					DisplayChinesCharacter(6,3,51,0);
					DisplayChinesCharacter(6,4,51,0);
					DisplayChinesCharacter(6,5,51,0);
					DisplayChinesCharacter(6,6,51,0);
					DisplayChinesCharacter(6,7,51,0);


				}
				
				while(1)
				{
					
					if(KeyStatu.Menu_Key_LongPress|KeyStatu.Menu_Key_ShortPress)
					{
						KeyStatu.Menu_Key_LongPress=0;
						KeyStatu.Menu_Key_ShortPress=0;
						LcdMenuStatus=Menu_EnterSet;
						goto DisplayMenu;
					}
					if(KeyStatu.Move_Key_Press)
					{
						KeyStatu.Move_Key_Press=0;


						++channle;
						
						if(channle>11)
						{
							channle=1;
						}
						if(channle<5)
						{
							DisplayChinesCharacter(0,0,17,0);
							DisplayChinesCharacter(2,0,18,0);
							DisplayChinesCharacter(4,0,19,0);
							DisplayChinesCharacter(6,0,20,0);
							

						}else if(channle==5)
						{
							DisplayChinesCharacter(0,0,18,0);
							DisplayChinesCharacter(2,0,19,0);
							DisplayChinesCharacter(4,0,20,0);
							DisplayChinesCharacter(6,0,21,0);
						}
						else if(channle==6)
						{
							DisplayChinesCharacter(0,0,19,0);
							DisplayChinesCharacter(2,0,20,0);
							DisplayChinesCharacter(4,0,21,0);
							DisplayChinesCharacter(6,0,71,0);
							DisplayChinesCharacterRightShift8bit(6,1,9,0);
						}			
						else if(channle==7)
						{
							DisplayChinesCharacter(0,0,20,0);
							DisplayChinesCharacter(2,0,21,0);
							
							DisplayChinesCharacter(4,0,71,0);
							DisplayChinesCharacterRightShift8bit(4,1,9,0);


							DisplayChinesCharacter(6,0,71,0);
							DisplayChinesCharacterRightShift8bit(6,1,10,0);

						}	

						else if(channle==8)
						{
							DisplayChinesCharacter(0,0,21,0);
				
							DisplayChinesCharacter(2,0,71,0);
							DisplayChinesCharacterRightShift8bit(2,1,9,0);

							DisplayChinesCharacter(4,0,71,0);
							DisplayChinesCharacterRightShift8bit(4,1,10,0);

							DisplayChinesCharacter(6,0,71,0);
							DisplayChinesCharacterRightShift8bit(6,1,11,0);

						}	
						else if(channle==9)
						{
							
							DisplayChinesCharacter(0,0,71,0);
							DisplayChinesCharacterRightShift8bit(0,1,9,0);

							DisplayChinesCharacter(2,0,71,0);
							DisplayChinesCharacterRightShift8bit(2,1,10,0);

							DisplayChinesCharacter(4,0,71,0);
							DisplayChinesCharacterRightShift8bit(4,1,11,0);
							
							DisplayChinesCharacter(6,0,72,0);
							DisplayChinesCharacterRightShift8bit(6,1,9,0);										

						}	
						else if(channle==10)
						{
							

							DisplayChinesCharacter(0,0,71,0);
							DisplayChinesCharacterRightShift8bit(0,1,10,0);

							DisplayChinesCharacter(2,0,71,0);
							DisplayChinesCharacterRightShift8bit(2,1,11,0);
							
							DisplayChinesCharacter(4,0,72,0);
							DisplayChinesCharacterRightShift8bit(4,1,9,0);	
							
							DisplayChinesCharacter(6,0,72,0);
							DisplayChinesCharacterRightShift8bit(6,1,10,0); 	

						}	
						else if(channle==11)
						{
							

							DisplayChinesCharacter(0,0,71,0);
							DisplayChinesCharacterRightShift8bit(0,1,11,0);
							
							DisplayChinesCharacter(2,0,72,0);
							DisplayChinesCharacterRightShift8bit(2,1,9,0);	
							
							DisplayChinesCharacter(4,0,72,0);
							DisplayChinesCharacterRightShift8bit(4,1,10,0); 
							
							DisplayChinesCharacter(6,0,72,0);
							DisplayChinesCharacterRightShift8bit(6,1,11,0); 

						}	

						
						DisplayChinesCharacter(0,1,74,0);�ƶ��ڷ���
						DisplayChinesCharacter(2,1,74,0);
						DisplayChinesCharacter(4,1,74,0);
						DisplayChinesCharacter(6,1,74,0);
						select+=2;
						if(select>6)
						{
							DisplayChinesCharacter(6,1,73,0);
							if(select>20)
							{
								DisplayChinesCharacter(6,1,74,0);
								select=0;
								DisplayChinesCharacter(select,1,73,0);
							}
							
						}
						else
						{
							DisplayChinesCharacter(select,1,73,0);
						}

						goto DisplayChannleLimitValue;
					}
					HAL_Delay(1000);
				}

			}
			else if(reverse_xpoint==(x+4)) 
			{
				printf("ϵͳ����\n");

				disp_clear();
				
				DisplayChinesCharacter(0,0,9,0);
				DisplayChinesCharacterRightShift8bit(0,1,11,0);
				DisplayChinesCharacter(0,1,16+3,0);
				DisplayChinesCharacterRightShift8bit(0,2,16+8,0);	
				DisplayChinesCharacter(0,2,16,0);		
				DisplayChinesCharacterRightShift8bit(0,3,26,0);
				DisplayChinesCharacter(0,3,16+3,0);
				DisplayChinesCharacterRightShift8bit(0,4,81,0);
				DisplayChinesCharacter(0,4,69,0);

				DisplayChinesCharacter(2,0,82,0);������
				DisplayChinesCharacter(2,1,39,0);
				DisplayChinesCharacter(2,2,83,0);
				DisplayChinesCharacter(2,3,45,0);
				DisplayChinesCharacter(2,4,26,0);
				DisplayChinesCharacter_s(2,5,84,2,0);
				

				DisplayChinesCharacter_s(4,0,36,2,0);�������
				DisplayChinesCharacter_s(4,2,88,2,0);
				DisplayChinesCharacter(4,4,26,0);
				DisplayChinesCharacter_s(4,5,86,2,0);
				
				DisplayChinesCharacter_s(6,0,36,2,0);�������
				DisplayChinesCharacter_s(6,2,90,2,0);
				DisplayChinesCharacter(6,4,26,0);
				DisplayChinesCharacter_s(6,5,86,2,0);

				while(1)
				{
					if(KeyStatu.Menu_Key_LongPress|KeyStatu.Menu_Key_ShortPress)
					{
						KeyStatu.Menu_Key_LongPress=0;
						KeyStatu.Menu_Key_ShortPress=0;
						
						goto DisplayMenu;
					}

					HAL_Delay(500);
				}
			}						
		}	

		HAL_Delay(500);
	}



}


void LcdShowSysInfor(void)
{
	uint8	i=0;
	disp_clear();		
	if(ReceData.ModuleType==NBModule)
	{
		DisplayChinesCharacter(0,0,69,0);
		DisplayChinesCharacterRightShift8bit(0,1,10,0);
		DisplayChinesCharacter(0,1,40,0);
		DisplayChinesCharacterRightShift8bit(0,2,92,0);
		DisplayChinesCharacter(0,2,9,0);
		DisplayChinesCharacterRightShift8bit(0,3,11,0);
		DisplayChinesCharacter(0,3,26,0);
		for(i=0;i<8;i++)
		{
			DisplayChinesCharacter(2,i,16+ReceData.IMEI[i*2]-'0',0);
			if(i==7)
			{
				break;
			}
			DisplayChinesCharacterLeftShift8bit(2,i,16+ReceData.IMEI[i*2+1]-'0',0);
		}
	}
	else	if(ReceData.ModuleType==LoraModule)
	{
		DisplayChinesCharacter(0,0,116,0);
		DisplayChinesCharacterRightShift8bit(0,1,119,0);
		DisplayChinesCharacter(0,1,122,0);
		DisplayChinesCharacterRightShift8bit(0,2,105,0); 
		DisplayChinesCharacter(0,2,40,0); 	
		DisplayChinesCharacterRightShift8bit(0,3,92,0); 
		DisplayChinesCharacter(0,3,9,0);
		DisplayChinesCharacterRightShift8bit(0,4,11,0);
		DisplayChinesCharacter(0,4,26,0);


		for(i=0;i<8;i++)
		{
			if(ReceData.DEVEUI[i*2]-'0'>=0&&ReceData.DEVEUI[i*2]-'0'<=9)
			{
				DisplayChinesCharacter(2,i,16+ReceData.DEVEUI[i*2]-'0',0);
			}
			else
			{
				DisplayChinesCharacter(2,i,105+ReceData.DEVEUI[i*2]-'a',0);
				
			}

			if(ReceData.DEVEUI[i*2+1]-'0'>=0&&ReceData.DEVEUI[i*2+1]-'0'<=9)
			{
				DisplayChinesCharacterLeftShift8bit(2,i,16+ReceData.DEVEUI[i*2+1]-'0',0);
			}
			else
			{
				DisplayChinesCharacterLeftShift8bit(2,i,105+ReceData.DEVEUI[i*2+1]-'a',0);
				
			}
		}


	}
	
	DisplayChinesCharacter_s(4,0,93,3,0);
	DisplayChinesCharacterRightShift8bit(4,3,69,0);
	DisplayChinesCharacter(4,3,26,0);

	     
	
	DisplayChinesCharacter_Dot(6,0,Version[0]+16-'0',0);
	DisplayChinesCharacter(6,1,Version[2]+16-'0',0);
	DisplayChinesCharacterLeftShift8bit(6,1,40,0);
	for(i=2;i<6;i++)
	{
		DisplayChinesCharacter(6,i,16+Version[i*2]-'0',0);
		DisplayChinesCharacterLeftShift8bit(6,i,16+Version[i*2+1]-'0',0);
	}

	
	while(1)
	{
		if(KeyStatu.Menu_Key_LongPress|KeyStatu.Menu_Key_ShortPress)
		{
			KeyStatu.Menu_Key_LongPress=0;
			KeyStatu.Menu_Key_ShortPress=0;
			LcdMenuStatus=Menu_ShowData;
			break;
		}
	
		HAL_Delay(500);
	}



}
int main(void)
{
	uint32	SysClk=0;
	uint8	i=0,x=0,y=0,reverse_xpoint=0,channle=0,select,h=0;
	HAL_Init();
	SystemClock_Config();
	ALLGPIO_Initial();
	CollectBorad_ResetActive;
	SysClk=HAL_RCC_GetPCLK1Freq();
	Print_UART_Init();
	SysTimeInitial();
	Commu_UART_Init();
	Bluetooth_UART_Init();
	BuzzerPWMInitial();
	
	WatchdogInitial();
	printf("\n%s-%s-%s\n",firmwareInf[0],firmwareInf[1],firmwareInf[2]);
	printf("HAL_RCC_GetPCLK1Freq=%10d\n\n",SysClk);

	memcpy((uint8*)&SysPara,(uint8*)InterFlashAddress,sizeof(Sys_Para));

	if(SysPara.thresholdVal_UsedDefault==Not_UsedDefaultValue)
	{

		
		printf("--->>>����ֵ\nC=%d ",SysPara.thresholdVal.CurThreshold_a);
		printf("%d ",SysPara.thresholdVal.CurThreshold_b);	
		printf("%d ",SysPara.thresholdVal.CurThreshold_c);	
		printf("%d\n",SysPara.thresholdVal.CurThreshold_r); 		
		
		printf("V=%d ",SysPara.thresholdVal.Vol_OverThreshold_a);
		  printf("%d ",SysPara.thresholdVal.Vol_OverThreshold_b);	
		 printf("%d\n",SysPara.thresholdVal.Vol_OverThreshold_c);	
		
		  printf("%d ",SysPara.thresholdVal.Vol_BelowThreshold_a);
		  printf("%d ",SysPara.thresholdVal.Vol_BelowThreshold_b);
		 printf("%d\n",SysPara.thresholdVal.Vol_BelowThreshold_c);
		
		printf("T=%d ",SysPara.thresholdVal.TemThreshold_a);
		printf("%d ",SysPara.thresholdVal.TemThreshold_b);
		printf("%d ",SysPara.thresholdVal.TemThreshold_c);
		printf("%d\n",SysPara.thresholdVal.TemThreshold_s);		


	}
	else
	{
		printf("--->>>Thershold Use Default Value\n");
		SysPara.thresholdVal.TemThreshold_a=50;	
		SysPara.thresholdVal.TemThreshold_b=50;	
		SysPara.thresholdVal.TemThreshold_c=50;	
		SysPara.thresholdVal.TemThreshold_s=50;	

		SysPara.thresholdVal.Vol_OverThreshold_a=250;
		SysPara.thresholdVal.Vol_OverThreshold_b=250;
		SysPara.thresholdVal.Vol_OverThreshold_c=250;

		SysPara.thresholdVal.Vol_BelowThreshold_a=200;
		SysPara.thresholdVal.Vol_BelowThreshold_b=200;
		SysPara.thresholdVal.Vol_BelowThreshold_c=200;

		SysPara.thresholdVal.CurThreshold_a=80;
		SysPara.thresholdVal.CurThreshold_b=80;
		SysPara.thresholdVal.CurThreshold_c=80;
		SysPara.thresholdVal.CurThreshold_r=5000;
		
	}

	SysPara.sendAlarmInforFlag=0;
	printf("%d\n",SysPara.thresholdVal.PowerThreshold);


	if(SysPara.ChannleStatus_UsedDefault==Not_UsedDefaultValue)
	{

		printf("--->>>ͨ������\nC=%02x ",SysPara.ChannleStatus.CurChannle_a);
		printf("%02x ",SysPara.ChannleStatus.CurChannle_b);
		printf("%02x ",SysPara.ChannleStatus.CurChannle_c);
		printf("%02x\n",SysPara.ChannleStatus.CurChannle_r);

		printf("V=%02x ",SysPara.ChannleStatus.VolChannle_a);
		printf("%02x ",SysPara.ChannleStatus.VolChannle_b);
		printf("%02x\n",SysPara.ChannleStatus.VolChannle_c);

		printf("T=%02x ",SysPara.ChannleStatus.TemChannle_a);
		printf("%02x ",SysPara.ChannleStatus.TemChannle_b);
		printf("%02x ",SysPara.ChannleStatus.TemChannle_c);
		printf("%02x\n",SysPara.ChannleStatus.TemChannle_s);

	}
	else
	{
		printf("--->>>ChannleEnalbe_Use Default Value\n");
		SysPara.ChannleStatus.CurChannle_a=Channle_Status_Open;
		SysPara.ChannleStatus.CurChannle_b=Channle_Status_Open;
		SysPara.ChannleStatus.CurChannle_c=Channle_Status_Open;
		SysPara.ChannleStatus.CurChannle_r=Channle_Status_Open;

		SysPara.ChannleStatus.VolChannle_a=Channle_Status_Open;
		SysPara.ChannleStatus.VolChannle_b=Channle_Status_Open;
		SysPara.ChannleStatus.VolChannle_c=Channle_Status_Open;

		SysPara.ChannleStatus.TemChannle_a=Channle_Status_Open;
		SysPara.ChannleStatus.TemChannle_b=Channle_Status_Open;
		SysPara.ChannleStatus.TemChannle_c=Channle_Status_Open;
		SysPara.ChannleStatus.TemChannle_s=Channle_Status_Open;	


	}


	WarnStatus.CurChannle_a_Warn=Cur_Warn_Normal;
	WarnStatus.CurChannle_b_Warn=Cur_Warn_Normal;
	WarnStatus.CurChannle_c_Warn=Cur_Warn_Normal;
	WarnStatus.CurChannle_r_Warn=Cur_Warn_Normal;
	
	WarnStatus.VolChannle_a_Warn=Vol_Warn_Normal;
	WarnStatus.VolChannle_b_Warn=Vol_Warn_Normal;
	WarnStatus.VolChannle_c_Warn=Vol_Warn_Normal;
	
	
	WarnStatus.TemChannle_a_Warn=Tem_Warn_Normal;
	WarnStatus.TemChannle_b_Warn=Tem_Warn_Normal;
	WarnStatus.TemChannle_c_Warn=Tem_Warn_Normal;
	WarnStatus.TemChannle_s_Warn=Tem_Warn_Normal;




	Bluetooth_ReceData->processed=1;
	HC06_Test();
	HAL_Delay(200);		
	HC06_ChangeName();
	HAL_Delay(200);	
	HC06_SetPassWord();

	
	Led_Run_ON;
	Led_Alarm_OFF;
	Led_Malfunction_OFF;
	
	LcdMenuStatus=Menu_Inital;
	
	LedStatus.run_led=LED_Disable;
	LedStatus.alarm_led=LED_Disable;
	LedStatus.malfunction_led=LED_Disable;
	LedStatus.missingPhase_led=LED_Disable;

	ReceData.ModuleType=NotDetectModule;
	
	while(1)
	{
		if(Sys_Rest_Cnt>24*60*60*1000*3)
		{
			printf("--->>CollectBorad_ResetActive\n");
			CollectBorad_ResetActive;
			HAL_Delay(1000);
			CollectBorad_ResetNotActive;
		}
		FeedWatchDog();
		HC06_ReceiveData(); 
		switch  (LcdMenuStatus)
		{
			case Menu_Inital:
				 CollectBorad_ResetNotActive;
				 BUZZER_ON;
				 HAL_Delay(500);
				 BUZZER_OFF;
				 printf("��ʼ��\n");
				 lcd_init();	   ��ʹ��
				 disp_clear();	  ����				
				 DisplayOpenLog();
				 LcdMenuStatus=Menu_ShowData;
				 HAL_Delay(3000);				
                 break;
			case Menu_ShowData:
				 ��ʾ����\n");
				 LcdShowData(); 
                 break;				
		 	case Menu_EnterSet:
				 LcdEnterMenu();
				 break;
 			case Menu_ShowSysInfor:
				 LcdShowSysInfor();	
				 break;
			default:  break;	 
		}
	}
	

}


void Error_Handler(void)
{
	printf("--->>Error\n");
}
